package top.zackyoung.bbs.controller;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zackyoung.bbs.entity.ResultMsg;
import top.zackyoung.bbs.entity.Search;
import top.zackyoung.bbs.service.ArticlesService;

import javax.annotation.Resource;

@RestController
@RequestMapping("/article")
public class ArticlesController {

    @Resource
    private ArticlesService articlesService;

    @RequestMapping("/search")
    public ResultMsg search(Search search){

        return articlesService.getByArticleLike(search);
    }

    @RequestMapping("/details/{id}")
    public ResultMsg search(@PathVariable Integer id){

        return articlesService.getByArticleId(id);
    }

    @RequestMapping("/user/{userId}")
    public ResultMsg search(@PathVariable String userId,Search search){
        search.setUserId(userId);

        return articlesService.findByUserId(search);
    }

    @RequestMapping("/tag/{tagId}")
    public ResultMsg search(@PathVariable Integer tagId,Search search){
        search.setType(tagId);
        return articlesService.findByTagId(search);
    }

    @RequestMapping("/delete/{articleId}")
    public ResultMsg delete(@PathVariable Integer articleId){

        return articlesService.deleteByArticleId(articleId);
    }

}
